package cn.edu.nankai.bookstore.controller.receiver;

import cn.edu.nankai.bookstore.domain.po.Receiver;
import cn.edu.nankai.bookstore.service.ReceiverService;
import cn.edu.nankai.bookstore.service.impl.ReceiverServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ModifyReceiverServlet", value = "/ModifyReceiverServlet")
public class ModifyReceiverServlet extends HttpServlet {
    private ReceiverService receiverService = new ReceiverServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if(session.getAttribute("su") == null){
            response.getWriter().write("{access:'deny'}");
            return;
        }
        String newName = (String) request.getParameter("newname");
        int id = Integer.parseInt((String) request.getParameter("id"));
        Boolean status = receiverService.modify(new Receiver(id, newName));
        response.getWriter().write(status.toString());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
